package com.huaao.micropolice.core.repository.system;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

import org.springframework.stereotype.Repository;

import com.huaao.micropolice.core.model.system.Menu_Dept;
import com.huaao.micropolice.core.model.system.Role;
import com.huaao.micropolice.core.repository.BaseDao;

@Repository
public class MenuDeptDao extends BaseDao{

	public void clearDept(Role role, String menuId) {
		Set<Menu_Dept> set = new HashSet<Menu_Dept>();
		for(Menu_Dept menu_Dept : role.getMenuDepts()){
			if(menu_Dept.getMenu().getId().equals(menuId)){
				set.add(menu_Dept);
			}
		}
		role.getMenuDepts().removeAll(set);
	}
	
	public Set<Menu_Dept> filter(Set<Role> roles , String menuId){
		Set<Menu_Dept> set = new HashSet<Menu_Dept>();
		for(Role role : roles){
			set.addAll(filter(role,menuId));
		}
		return set;
	}

	private Collection<? extends Menu_Dept> filter(Role role, String menuId) {
		Set<Menu_Dept> set = new HashSet<Menu_Dept>();
		for(Menu_Dept md : role.getMenuDepts()){
			if(md.getMenu().getId().equals(menuId)){
				set.add(md);
			}
		}
		return set;
	}
}
